<template>
  <div>
    <el-dialog title="编辑课程体系" :visible="true" width="80%" @close="handleClose">
      <el-form ref="form" :model="form" label-width="80px">
        <el-form-item label="名称：" required>
          <el-input v-model="form.name" placeholder="请输入课程体系名称"></el-input>
        </el-form-item>
      </el-form>



      <span slot="footer" class="dialog-footer">
        <el-button @click="handleClose">取 消</el-button>
        <el-button type="primary" @click="handleAdd">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { courseLevelInfo, editCourseLevel } from "@/api/course";
export default {
  props: {
    id: {
      type: String | Number
    }
  },
  data() {
    return {
      form: {
        name: ''
      }

    }
  },
  created() {
    this.getInfo();
  },
  methods: {
    async getInfo() {
      let res = await courseLevelInfo({ id: this.id });
      this.form.name = res.data.name
    },
    async editCourseLevel() {
      let res = await editCourseLevel({
        name:this.form.name,
        id:this.id
      });
      this.$message({
        message: '编辑成功！',
        type: 'success'
      });
      this.$emit('success')
    },
    handleClose() {
      this.$emit('close')
    },
    handleAdd() {
      if (this.form.name === '') {
        this.$message({
          message: '请输入课程体系名称！',
          type: 'warning'
        });
      } else {
        this.editCourseLevel();
      }
    },

  },
}
</script>
<style lang="scss" scoped>
</style>
